Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional sorting functions #1776

Merged
merged 2 commits into from
Jan 14, 2025

Conversation

DhivinX
Copy link
Collaborator

@DhivinX DhivinX commented Jan 14, 2025

TreeViewPlugin can now accept its own sorting functions as constructor arguments.
Useful when the user wants to define their own way of sorting elements in the tree.

Example of use:

const treeView = new TreeViewPlugin(viewer, {
  // ...
  sortNodes: true,

  // sort numerically if node titles are numeric
  defaultSortFunction: (node1, node2) => { 
    const isNumber1 = !isNaN(Number(node1.title));
    const isNumber2 = !isNaN(Number(node2.title));

    if (isNumber1 && isNumber2) {
      return Number(node1.title) - Number(node2.title);
    } else {
      return node1.title.localeCompare(node2.title);
    }
  }
});

@DhivinX DhivinX requested a review from xeolabs January 14, 2025 21:11
@xeolabs xeolabs merged commit 8f1d4ee into xeokit:master Jan 14, 2025
2 checks passed
@DhivinX DhivinX deleted the feat/optional-sorting-functions branch January 14, 2025 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants